package cn.netty.exemple6;

import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

public class SubReqClientHandle extends ChannelHandlerAdapter {


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

        if (msg instanceof OrderResponse){
            OrderResponse msg1 = (OrderResponse) msg;
            //do something
            System.out.println(msg1.toString());
        }

    }


    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        Order order = new Order();
        order.setId(1);
        order.setAddress("广州市天河区");
        order.setUserName("陈志鹏");
        order.setPhoneNumber("13000000000");
        order.setProductName(" netty in action");
        ctx.writeAndFlush(order);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        System.out.println("server is error "+ cause.getMessage());

        ctx.close();
    }
}
